/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package coalescent.nb.jobs.properties.editors;

import coalescent.nb.jobs.properties.Propertys_Coa;
import org.netbeans.validation.api.Problems;
import org.netbeans.validation.api.Validator;

import java.beans.PropertyEditorSupport;

/**
 * @author Susanta Tewari
 */
public class AnPropertyEditor extends PropertyEditorSupport {

    /** Field description */
    private final Validator validator =
        Propertys_Coa.of_Data_An("coalescent.builder.An").getValidator();

    /**
     * Method description
     *
     *
     * @return
     */
    @Override
    public String getAsText() {

        final String d = (String) getValue();

        if (d == null) {
            return "No Value";
        }

        return d;
    }

    /**
     * Method description
     *
     *
     * @param s
     *
     * @throws IllegalArgumentException
     */
    @Override
    public void setAsText(final String s) throws IllegalArgumentException {

        final Problems problems = new Problems();

        if (!validator.validate(problems, null, s)) {
            throw new IllegalArgumentException(problems.getLeadProblem().getMessage());
        }

        setValue(s);
    }
}
